Code for the Hotel Management System

We’ve reviewed different aspects of the hotel management system and observed the attributes attached to the problem using various UML diagrams. Let’s explore the more practical side of things, where we will work on implementing the hotel management system using multiple languages. This is usually the last step in an object-oriented design interview process.

We have chosen the following languages to write the skeleton code of the different classes present in the hotel management system:

  • Java

  • C#

  • Python

  • C++

  • JavaScript

Hotel management system classes#

In this section, we’ll provide the skeleton code of the classes designed in the class diagram lesson.

Note: For simplicity, we are not defining getter and setter functions. The reader can assume that all class attributes are private and accessed through their respective public getter methods and modified only through their public methods function.

Enumerations#

First, we will define all the enumerations required in the hotel management system. According to the class diagram, there are six enumerations used in the system, i.e., RoomStyle, RoomStatus, BookingStatus, AccountStatus, AccountType, and PaymentStatus. The code to implement these enumerations is as follows:

Note: JavaScript does not support enumerations, so we will be using the Object.freeze() method as an alternative that freezes an object and prevents further modifications.

Enum definitions

Address and account#

This section contains the Address and Account classes. Here, the Address class is used as a custom data type. The implementation of these classes is shown below:

The Address and Account classes

Person#

Person is an abstract class that represents the various people or actors that can interact with the system. There are four types of persons: Guest, Receptionist, Server, and Housekeeper. The implementation of the mentioned classes is shown below:

Person and its child classes

Service#

Service is an abstract class, and this section represents different charges, Amenity, RoomService, and KitchenService), against a booking. The code to implement these classes is shown below:

Service and its derived classes

Invoice#

This section contains information on the Invoice class to create a bill. The implementation of this class is represented below:

The Invoice class

Room booking#

RoomBooking is a class responsible for managing the bookings for a room. The implementation of this class is given below:

The RoomBooking class

Bill transaction#

After generating an invoice, a customer needs to pay the bill to confirm the booking of the room. A BillTransaction class is required to store the information of bill payment. Three ways to pay the bill are check transactions, cash transactions, and credit card transactions.

BillTransaction and its derived classes

Notification#

The Notification class is another abstract class responsible for sending notifications, with the SMSNotification and EmailNotification classes as its child. The implementation of this class is given below:

Notification and its derived classes

Room, room key and room housekeeping#

The Room class represents a room in the hotel. RoomKey is a class used to express the electronic key card and the RoomHousekeeping is a class used to keep track of all the housekeeping records for the rooms. The implementation of these classes is given below:

The Room, RoomKey and RoomHousekeeping classes

Search and catalog#

Search is an interface, and the Catalog class implements the search interface to help in the room search. The code to perform this functionality is presented below:

The Search interface and Catalog class

Hotel and hotel branch#

The Hotel class is the base class of the system that represents the hotel. The implementation of these classes is given below:

The HotelBranch and Hotel classes

Wrapping up#

We've explored the complete design of a hotel management system in this chapter. We've looked at how a basic hotel management system can be visualized using various UML diagrams and designed using object-oriented principles and design patterns.

Activity Diagram for the Hotel Management System

Getting Ready: The Amazon Online Shopping System